//
//  SISSKPIDetailViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/16.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSKPIDetailViewController.h"
#import "SWForm.h"
#import "SISSJsonRequestNetworkingManager+Registration.h"
#import "SISSKPIEnrollViewController.h"

@interface SISSKPIDetailViewController ()

@property (weak, nonatomic) SWFormItem *applyDateItem;
@property (weak, nonatomic) SWFormItem *checkStatusItem;
@property (weak, nonatomic) SWFormItem *performanceRateItem;
@property (weak, nonatomic) SWFormItem *performanceScoreItem;

@property (weak, nonatomic) SWFormItem *businessTypeItem;
@property (weak, nonatomic) SWFormItem *houseTypeItem;
@property (weak, nonatomic) SWFormItem *certificateNoItem;
@property (weak, nonatomic) SWFormItem *contractNoItem;
@property (weak, nonatomic) SWFormItem *KPIStarLevelItem;

@property (weak, nonatomic) SWFormItem *dealTimeItem;
@property (weak, nonatomic) SWFormItem *regionItem;
@property (weak, nonatomic) SWFormItem *propertyAddressItem;
@property (weak, nonatomic) SWFormItem *communityItem;
@property (weak, nonatomic) SWFormItem *buildingItem;
@property (weak, nonatomic) SWFormItem *roomItem;
@property (weak, nonatomic) SWFormItem *nameItem;
@property (weak, nonatomic) SWFormItem *mobileItem;
@property (weak, nonatomic) SWFormItem *companyItem;
@property (weak, nonatomic) SWFormItem *contractEntryTimeItem;
@property (weak, nonatomic) SWFormItem *receivingTimeItem;
@property (weak, nonatomic) SWFormItem *organNameItem;
///
@property (strong, nonatomic) NSMutableArray *sellSecondItems;
@property (strong, nonatomic) NSMutableArray *sellThirdItems;

@property (strong, nonatomic) NSMutableArray *rentSecondItems;
@property (strong, nonatomic) NSMutableArray *rentThirdItems;

///
@property (weak, nonatomic) UIButton *changeButton;
@property (weak, nonatomic) UIButton *deleteButton;

///
@property (strong, nonatomic) SISSKPIDetailModel *KPIDetailModel;

@end

@implementation SISSKPIDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColor.groupTableViewBackgroundColor;
    [self initUI];
    
    if (self.isAppyIn && self.isChange) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    }
}

- (void)back {
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:NSClassFromString(@"SISSMyKPIViewController")]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (void)setID:(NSString *)ID {
    _ID = ID;
    WeakSelf
    [kJsonRequestNetworkingManager requestAchievementDetailWithID:ID successBlock:^(SISSKPIDetailModel *KPIDetailModel) {
        
        weakSelf.KPIDetailModel = KPIDetailModel;
        weakSelf.KPIDetailModel.ID = weakSelf.ID;
        
        weakSelf.changeButton.hidden = [KPIDetailModel.businessState isEqualToString:@"1"];
        weakSelf.deleteButton.hidden = [KPIDetailModel.businessState isEqualToString:@"1"];
        
        if (weakSelf.mutableItems.count == 3) [weakSelf.mutableItems removeLastObject];
        if (weakSelf.mutableItems.count == 2) [weakSelf.mutableItems removeLastObject];
        
        UIView *sectionFooterView = [[UIView alloc] init];
        sectionFooterView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        if ([KPIDetailModel.businessType isEqualToString:@"买卖"]) {
            weakSelf.contractNoItem.title = @"合同编号：";
            weakSelf.regionItem.title = @"物业所属行政区：";
            weakSelf.organNameItem.title = @"网签机构名称：";
            SWFormSectionItem *secondSectionItem = [SWFormSectionItem sw_sectionItem:weakSelf.sellSecondItems];
            secondSectionItem.footerHeight = 20;
            secondSectionItem.footerView = sectionFooterView;
            SWFormSectionItem *thirdSectionItem = [SWFormSectionItem sw_sectionItem:weakSelf.sellThirdItems];
            [weakSelf.mutableItems addObject:secondSectionItem];
            [weakSelf.mutableItems addObject:thirdSectionItem];
        } else {
            weakSelf.contractNoItem.title = @"机构合同编号：";
            weakSelf.regionItem.title = @"地区：";
            weakSelf.organNameItem.title = @"合同落款机构：";
            SWFormSectionItem *secondSectionItem = [SWFormSectionItem sw_sectionItem:weakSelf.rentSecondItems];
            secondSectionItem.footerHeight = 20;
            secondSectionItem.footerView = sectionFooterView;
            SWFormSectionItem *thirdSectionItem = [SWFormSectionItem sw_sectionItem:weakSelf.rentThirdItems];
            [weakSelf.mutableItems addObject:secondSectionItem];
            [weakSelf.mutableItems addObject:thirdSectionItem];
        }
        
        weakSelf.applyDateItem.info = [NSDate yyr_stringToString:KPIDetailModel.insertTime];
        NSString *businessState = @"";
        if ([KPIDetailModel.businessState isEqualToString:@"0"]) {
            businessState = @"未审批";
        } else if ([KPIDetailModel.businessState isEqualToString:@"1"]) {
            businessState = @"已审批";
        } else if ([KPIDetailModel.businessState isEqualToString:@"2"]) {
            businessState = @"已否认";
        }
        weakSelf.checkStatusItem.info = businessState;
        weakSelf.performanceRateItem.info = [NSString stringWithFormat:@"%@%@",KPIDetailModel.rate,@"%"];
        weakSelf.performanceScoreItem.info = KPIDetailModel.achievementValue;
        
        weakSelf.businessTypeItem.info = KPIDetailModel.businessType;
        weakSelf.houseTypeItem.info = KPIDetailModel.houseType.length > 0 ? KPIDetailModel.houseType : @" ";
        weakSelf.certificateNoItem.info = KPIDetailModel.certificateNum.length > 0 ? KPIDetailModel.certificateNum : @" ";
        weakSelf.contractNoItem.info = KPIDetailModel.contractNum.length > 0 ? KPIDetailModel.contractNum : @" ";
        weakSelf.KPIStarLevelItem.info = [NSString stringWithFormat:@"%@ - %@",[NSDate yyr_stringToString:KPIDetailModel.startTime],[NSDate yyr_stringToString:KPIDetailModel.endTime]];
        
        weakSelf.dealTimeItem.info = KPIDetailModel.dealTime.length > 0 ? [NSDate yyr_stringToString:KPIDetailModel.dealTime] : @" ";
        weakSelf.regionItem.info = [NSString stringWithFormat:@"%@ %@ %@",KPIDetailModel.province ? KPIDetailModel.province : @"",KPIDetailModel.city ? KPIDetailModel.city : @"",KPIDetailModel.district ? KPIDetailModel.district : @""];
//        weakSelf.propertyAddressItem.info = KPIDetailModel..length > 0 ? KPIDetailModel. : @" ";
        weakSelf.communityItem.info = KPIDetailModel.neighbourhood.length > 0 ? KPIDetailModel.neighbourhood : @" ";
        weakSelf.buildingItem.info = KPIDetailModel.b_num.length > 0 ? KPIDetailModel.b_num : @" ";
        weakSelf.roomItem.info = KPIDetailModel.d_num.length > 0 ? KPIDetailModel.d_num : @" ";
        
        weakSelf.organNameItem.info = KPIDetailModel.organName.length > 0 ? KPIDetailModel.organName : @" ";
        
//        weakSelf.companyItem.info = KPIDetailModel..length > 0 ? KPIDetailModel. : @" ";
//        weakSelf.contractEntryTimeItem.info = KPIDetailModel..length > 0 ? KPIDetailModel. : @" ";
//        weakSelf.receivingTimeItem.info = KPIDetailModel..length > 0 ? KPIDetailModel. : @" ";
        
        if ([KPIDetailModel.businessState isEqualToString:@"0"]) {
            weakSelf.nameItem.info = KPIDetailModel.name.length > 0 ? KPIDetailModel.name : @" ";
            weakSelf.mobileItem.info = KPIDetailModel.mobile.length > 0 ? KPIDetailModel.mobile : @" ";
        } else {
            NSMutableString *strM = [NSMutableString string];
            if (KPIDetailModel.name.length > 1) {
                for (NSInteger i = 0; i < KPIDetailModel.name.length - 1; i++) {
                    [strM appendString:@"*"];
                }
            }
            weakSelf.nameItem.info = KPIDetailModel.name.length > 1 ? [NSString stringWithFormat:@"%@%@",[KPIDetailModel.name substringToIndex:1],strM] : @" ";
            weakSelf.mobileItem.info = KPIDetailModel.mobile.length > 7 ? [NSString stringWithFormat:@"%@****%@",[KPIDetailModel.mobile substringToIndex:2],[KPIDetailModel.mobile substringFromIndex:7]] : @" ";
        }
        
        [weakSelf.formTableView reloadData];
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)initUI {
    
    NSMutableArray *firstItems = [NSMutableArray array];
    SWFormItem *applyDateItem = [SWFormItem sw_itemWithTitle:@"申报日期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [firstItems addObject:applyDateItem];
    self.applyDateItem = applyDateItem;
    
    SWFormItem *checkStatusItem = [SWFormItem sw_itemWithTitle:@"审核状态：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    [firstItems addObject:checkStatusItem];
    self.checkStatusItem = checkStatusItem;
    
    SWFormItem *performanceRateItem = [SWFormItem sw_itemWithTitle:@"业绩份额占比：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    [firstItems addObject:performanceRateItem];
    self.performanceRateItem = performanceRateItem;
    
    SWFormItem *performanceScoreItem = [SWFormItem sw_itemWithTitle:@"业绩值：" info:@" " itemType:SWFormItemTypeInputSelect editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    performanceScoreItem.images = @[[UIImage imageNamed:@"?-anz"]];
    WeakSelf
    performanceScoreItem.itemSelectCompletion = ^(SWFormItem * _Nonnull item) {
        [weakSelf alertActionAlertWithTitle:@"分值计算方式" message:@"套数=售单+租单*0.76*份额占比；\n住宅（含公寓）=1.34*非住宅*份额占比；\n占比份额由机构确定；" confirmTitle:@"关闭"];
    };
    [firstItems addObject:performanceScoreItem];
    self.performanceScoreItem = performanceScoreItem;
    SWFormSectionItem *firstSectionItem = [SWFormSectionItem sw_sectionItem:firstItems];
    firstSectionItem.footerHeight = 20;
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    firstSectionItem.footerView = footerView;
    
    NSMutableArray *secondItems = [NSMutableArray array];
    self.sellSecondItems = [NSMutableArray array];
    self.rentSecondItems = [NSMutableArray array];
    SWFormItem *businessTypeItem = [SWFormItem sw_itemWithTitle:@"业务类型：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [secondItems addObject:businessTypeItem];
    self.businessTypeItem = businessTypeItem;
    [self.sellSecondItems addObject:businessTypeItem];
    [self.rentSecondItems addObject:businessTypeItem];
    
    SWFormItem *houseTypeItem = [SWFormItem sw_itemWithTitle:@"房产类型：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    [secondItems addObject:houseTypeItem];
    self.houseTypeItem = houseTypeItem;
    [self.sellSecondItems addObject:houseTypeItem];
    //    [self.rentSecondItems addObject:houseTypeItem];
    
    SWFormItem *regionItem = [SWFormItem sw_itemWithTitle:@"地区：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.rentSecondItems addObject:regionItem];
    self.regionItem = regionItem;
    
    SWFormItem *communityItem = [SWFormItem sw_itemWithTitle:@"小区：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.sellSecondItems addObject:communityItem];
    [self.rentSecondItems addObject:communityItem];
    self.communityItem = communityItem;
    
    SWFormItem *buildingItem = [SWFormItem sw_itemWithTitle:@"楼栋：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.sellSecondItems addObject:buildingItem];
    [self.rentSecondItems addObject:buildingItem];
    self.buildingItem = buildingItem;
    
    SWFormItem *roomItem = [SWFormItem sw_itemWithTitle:@"房号：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.sellSecondItems addObject:roomItem];
    [self.rentSecondItems addObject:roomItem];
    self.roomItem = roomItem;
    
    SWFormItem *organNameItem = [SWFormItem sw_itemWithTitle:@"网签机构名称：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.sellSecondItems addObject:organNameItem];
    self.organNameItem = organNameItem;
    
    SWFormItem *nameItem = [SWFormItem sw_itemWithTitle:@"租客（业主）姓名：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.rentSecondItems addObject:nameItem];
    self.nameItem = nameItem;
    
    SWFormItem *mobileItem = [SWFormItem sw_itemWithTitle:@"租客（业主）电话：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    [self.rentSecondItems addObject:mobileItem];
    self.mobileItem = mobileItem;
    
    SWFormItem *certificateNoItem = [SWFormItem sw_itemWithTitle:@"不动产权证书编码：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    //    [secondItems addObject:certificateNoItem];
    self.certificateNoItem = certificateNoItem;
    [self.sellSecondItems addObject:certificateNoItem];
    
    SWFormItem *dealTimeItem = [SWFormItem sw_itemWithTitle:@"成交日期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    //    [secondItems addObject:dealTimeItem];
    self.dealTimeItem = dealTimeItem;
    [self.rentSecondItems addObject:dealTimeItem];
    
    SWFormItem *contractNoItem = [SWFormItem sw_itemWithTitle:@"合同编号：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    [secondItems addObject:contractNoItem];
    self.contractNoItem = contractNoItem;
    [self.sellSecondItems addObject:contractNoItem];
    [self.rentSecondItems addObject:contractNoItem];
    
    [self.rentSecondItems addObject:organNameItem];
    
    SWFormItem *KPIStarLevelItem = [SWFormItem sw_itemWithTitle:@"业绩所属星级周期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
    
    [secondItems addObject:KPIStarLevelItem];
    self.KPIStarLevelItem = KPIStarLevelItem;
    [self.sellSecondItems addObject:KPIStarLevelItem];
    [self.rentSecondItems addObject:KPIStarLevelItem];
    
    SWFormSectionItem *secondSectionItem = [SWFormSectionItem sw_sectionItem:secondItems];
    
    
    [self.mutableItems addObject:firstSectionItem];
    [self.mutableItems addObject:secondSectionItem];
    
    if (!self.isAppyIn) {
        self.formTableView.tableFooterView = [self footerView];
        [self.formTableView layoutIfNeeded];
    }
}
#pragma mark - UI
//- (void)initUI {
//
//    NSMutableArray *firstItems = [NSMutableArray array];
//    SWFormItem *applyDateItem = [SWFormItem sw_itemWithTitle:@"申报日期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [firstItems addObject:applyDateItem];
//    self.applyDateItem = applyDateItem;
//
//    SWFormItem *checkStatusItem = [SWFormItem sw_itemWithTitle:@"审核状态：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    [firstItems addObject:checkStatusItem];
//    self.checkStatusItem = checkStatusItem;
//
//    SWFormItem *performanceRateItem = [SWFormItem sw_itemWithTitle:@"业绩份额占比：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    [firstItems addObject:performanceRateItem];
//    self.performanceRateItem = performanceRateItem;
//
//    SWFormItem *performanceScoreItem = [SWFormItem sw_itemWithTitle:@"业绩值：" info:@" " itemType:SWFormItemTypeInputSelect editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    performanceScoreItem.images = @[[UIImage imageNamed:@"?-anz"]];
//    WeakSelf
//    performanceScoreItem.itemSelectCompletion = ^(SWFormItem * _Nonnull item) {
//        [weakSelf alertActionAlertWithTitle:@"分值计算方式" message:@"套数=售单+租单*0.76*份额占比；\n住宅（含公寓）=1.34*非住宅*份额占比；\n占比份额由机构确定；" confirmTitle:@"关闭"];
//    };
//    [firstItems addObject:performanceScoreItem];
//    self.performanceScoreItem = performanceScoreItem;
//    SWFormSectionItem *firstSectionItem = [SWFormSectionItem sw_sectionItem:firstItems];
//    firstSectionItem.footerHeight = 20;
//    UIView *footerView = [[UIView alloc] init];
//    footerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    firstSectionItem.footerView = footerView;
//
//
//    NSMutableArray *secondItems = [NSMutableArray array];
//    self.sellSecondItems = [NSMutableArray array];
//    self.rentSecondItems = [NSMutableArray array];
//    SWFormItem *businessTypeItem = [SWFormItem sw_itemWithTitle:@"业务类型：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [secondItems addObject:businessTypeItem];
//    self.businessTypeItem = businessTypeItem;
//    [self.sellSecondItems addObject:businessTypeItem];
//    [self.rentSecondItems addObject:businessTypeItem];
//
//    SWFormItem *houseTypeItem = [SWFormItem sw_itemWithTitle:@"房产类型：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    [secondItems addObject:houseTypeItem];
//    self.houseTypeItem = houseTypeItem;
//    [self.sellSecondItems addObject:houseTypeItem];
//    [self.rentSecondItems addObject:houseTypeItem];
//
//    SWFormItem *certificateNoItem = [SWFormItem sw_itemWithTitle:@"不动产权证书编码：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    //    [secondItems addObject:certificateNoItem];
//    self.certificateNoItem = certificateNoItem;
//    [self.sellSecondItems addObject:certificateNoItem];
//
//    SWFormItem *contractNoItem = [SWFormItem sw_itemWithTitle:@"合同编号：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
////    [secondItems addObject:contractNoItem];
//    self.contractNoItem = contractNoItem;
//    [self.sellSecondItems addObject:contractNoItem];
//
//    SWFormItem *KPIStarLevelItem = [SWFormItem sw_itemWithTitle:@"业绩所属星级周期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    [secondItems addObject:KPIStarLevelItem];
//    self.KPIStarLevelItem = KPIStarLevelItem;
//    [self.sellSecondItems addObject:KPIStarLevelItem];
//    [self.rentSecondItems addObject:KPIStarLevelItem];
//
//    SWFormSectionItem *secondSectionItem = [SWFormSectionItem sw_sectionItem:secondItems];
//    secondSectionItem.footerHeight = 20;
//    secondSectionItem.footerView = footerView;
//
//    NSMutableArray *thirdItems = [NSMutableArray array];
//    self.sellThirdItems = [NSMutableArray array];
//    self.rentThirdItems = [NSMutableArray array];
//
//    SWFormItem *dealTimeItem = [SWFormItem sw_itemWithTitle:@"成交日期：" info:@" " itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//
//    //    [secondItems addObject:dealTimeItem];
//    self.dealTimeItem = dealTimeItem;
//    [self.rentThirdItems addObject:dealTimeItem];
//
//    [self.rentThirdItems addObject:contractNoItem];
//
//    SWFormItem *regionItem = [SWFormItem sw_itemWithTitle:@"地区：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.rentThirdItems addObject:regionItem];
//    [self.sellThirdItems addObject:regionItem];
//    self.regionItem = regionItem;
//
//    SWFormItem *propertyAddressItem = [SWFormItem sw_itemWithTitle:@"物业地址：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:propertyAddressItem];
//    self.propertyAddressItem = propertyAddressItem;
//
//    SWFormItem *communityItem = [SWFormItem sw_itemWithTitle:@"小区：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [thirdItems addObject:communityItem];
//    [self.sellThirdItems addObject:communityItem];
//    [self.rentThirdItems addObject:communityItem];
//    self.communityItem = communityItem;
//
//    SWFormItem *buildingItem = [SWFormItem sw_itemWithTitle:@"楼栋：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:buildingItem];
//    [self.rentThirdItems addObject:buildingItem];
//    self.buildingItem = buildingItem;
//
//    SWFormItem *roomItem = [SWFormItem sw_itemWithTitle:@"房号：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:roomItem];
//    [self.rentThirdItems addObject:roomItem];
//    self.roomItem = roomItem;
//
//    SWFormItem *nameItem = [SWFormItem sw_itemWithTitle:@"租客（业主）姓名：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.rentThirdItems addObject:nameItem];
//    self.nameItem = nameItem;
//
//    SWFormItem *mobileItem = [SWFormItem sw_itemWithTitle:@"租客（业主）电话：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.rentThirdItems addObject:mobileItem];
//    self.mobileItem = mobileItem;
//
//    SWFormItem *companyItem = [SWFormItem sw_itemWithTitle:@"成交公司：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:companyItem];
//    self.companyItem = companyItem;
//
//    SWFormItem *contractEntryTimeItem = [SWFormItem sw_itemWithTitle:@"合同录入时间：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:contractEntryTimeItem];
//    self.contractEntryTimeItem = contractEntryTimeItem;
//
//    SWFormItem *receivingTimeItem = [SWFormItem sw_itemWithTitle:@"收文时间：" info:@"" itemType:SWFormItemTypeInput editable:NO required:NO keyboardType:UIKeyboardTypeDefault];
//    [self.sellThirdItems addObject:receivingTimeItem];
//    self.receivingTimeItem = receivingTimeItem;
//
//    SWFormSectionItem *thirdSectionItem = [SWFormSectionItem sw_sectionItem:thirdItems];
//
//    [self.mutableItems addObject:firstSectionItem];
//    [self.mutableItems addObject:secondSectionItem];
//    [self.mutableItems addObject:thirdSectionItem];
//
//    if (!self.isAppyIn) {
//        self.formTableView.tableFooterView = [self footerView];
//        [self.formTableView layoutIfNeeded];
//    }
//}

- (void)changeButtonClickAction {
    
    SISSKPIEnrollViewController *vc = [[SISSKPIEnrollViewController alloc] init];
    vc.KPIDetailModel = self.KPIDetailModel;
    vc.title = @"业绩指标申报修改";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)deleteButtonClickAction {
    [kJsonRequestNetworkingManager deleteAchievementDetailWithID:self.ID successBlock:^(id responseObject) {
        if ([responseObject[@"code"] integerValue] == 200) {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [SISSTools showSVTitle:@"删除成功！" andTime:1.0 andColor:YES];
            }];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (self.deleteComplete) {
                    self.deleteComplete();
                }
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}


/**
 创建footer
 */
- (UIView *)footerView {
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 160)];
    
    UIButton *changeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    changeButton.backgroundColor = MAIN_COLOR;
    changeButton.layer.cornerRadius = 8;
    changeButton.layer.masksToBounds = YES;
    changeButton.hidden = YES;
    [changeButton setTitle:@"修改" forState:UIControlStateNormal];
    [changeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [changeButton addTarget:self action:@selector(changeButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:changeButton];
    self.changeButton = changeButton;
    
    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
    deleteButton.backgroundColor = UIColor.redColor;
    deleteButton.layer.cornerRadius = 8;
    deleteButton.layer.masksToBounds = YES;
    deleteButton.hidden = YES;
    [deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(deleteButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:deleteButton];
    self.deleteButton = deleteButton;
    
    WeakSelf
    CGSize buttonSize = CGSizeMake(SCREEN_WIDTH * 0.8, 48);
    [self.changeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@32);
        make.centerX.equalTo(footer.mas_centerX);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.changeButton.mas_bottom).offset(2 * globelMargin);
        make.centerX.equalTo(footer.mas_centerX);
        make.size.equalTo(weakSelf.changeButton);
    }];
    
    return footer;
}

@end
